<template>
  <div class="bottom">
    <!-- 输入框 -->
    <van-cell-group>
      <van-field
        v-model="tel"
        label="手机号"
        placeholder="请输入手机号"
        autofocus
      />
    </van-cell-group>
    <!-- 登录按钮 -->
    <van-button
      round
      type="info"
      size="large"
      color="linear-gradient(to right, #ff6034, #ee0a24)"
      :disabled="flag"
      @click="next"
      
      >下一步
    </van-button>
  </div>
</template>

<script>
import { docheckphone } from "../../api/user";
import Vue from "vue";
import { Dialog } from "vant";
Vue.use(Dialog);
export default {
  data() {
    return {
      tel: "",
      //   flag:true
    };
  },
  computed: {
    flag() {
      if (/^1[3456789]\d{9}$/.test(this.tel)) {
        return false;
      } else {
        return true;
      }
    },
  },
  methods: {
    next() {
      //  检测是否被注册
      docheckphone({ tel: this.tel }).then((res) => {
        console.log(res.data.code);
        switch (res.data.code) {
          case "10005":
            Dialog.confirm({
              message: "用户名已存在，是否登录",
            })
              .then(() => {
                // on confirm
                this.$router.back();
              })
              .catch(() => {
                // on cancel
              });
            break;
          case "200":
            localStorage.setItem("tel",this.tel)
            this.$router.push("/register/two");
            break;
          default:
            break;
        }
      });
    },
  },
};
</script>

<style scoped>
.bottom {
  width: 85%;
  margin: 10px auto;
}
</style>